package com.pzr.soccer.plan.controller;

import com.pzr.soccer.plan.dao.PlanRepository;
import com.pzr.soccer.plan.domain.Plan;
import com.pzr.soccer.plan.service.ScanChangeGameProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;


/**
 * @Author pzr
 * @date:2021-12-18-18:14
 * @Description:
 **/
@RestController
@RequestMapping("/test/plan")
public class TestPlanController {
    @Autowired
    MongoOperations mongoOperations;
    @Autowired
    ScanChangeGameProcessor scanChangeGameProcessor;
    @Autowired
    PlanRepository planRepository;

    @PostMapping("/add")
    public Plan addPlan(@RequestBody Plan plan){
        return planRepository.saveAndNotify(plan);
    }

    @DeleteMapping("/delete")
    public void deletePlan(@RequestBody Plan plan){
         planRepository.removeAndNotify(plan);
    }

    @GetMapping("/all")
    public List<Plan> getAllPlans(){
        return mongoOperations.findAll(Plan.class);
    }

    @GetMapping("/allFromMemory")
    public CopyOnWriteArrayList<Plan> getAllPlansFromMemory(){
        return scanChangeGameProcessor.getPlans();
    }
}
